<?php

//访问计数器
function counter(){
	$file = 'counter.txt';
	if(!file_exists($file)){
		$num = 0;
		$cf = fopen($file,"w");
		fwrite($cf,$num);
		fclose($cf);
	}else{
		$cf = fopen($file,"rw");
		//$num = fread($cf,filesize($file));
		$num = fgets($cf,'1024');//如果没有后面的数字的话，将默认读取到10又返回
		fclose($cf);
	}
	if($num !=''){
		$num++;
	}else{
		$num = 0;
	}
	$cf = fopen($file,"w");
	fwrite($cf,$num);
	fclose($cf);
	return $num;		
}

?>


<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>访问统计</title>
	</head>
	<body>
		<h1>欢迎访问</h1>
		<hr /><br />
		<center>您是第&nbsp;<font color="red"><?php echo counter(); ?></font>&nbsp;位访客</center>
	</body>
</html>